<template>
	<view style="width: 100%;">
		<view style="width: 100%;display: flex;justify-content: space-between;padding: 30rpx 50rpx;margin:20rpx auto;">
			<view @click="showChangeNote = true" style="display: flex;flex-direction: column;align-items: center;">
				<image src="/static/images/icon_note.png" style="width: 50rpx;height: 50rpx;" mode=""></image>
				<text style="margin-top: 10rpx;color: #515151;">
					签名
				</text>
			</view>
			<view @click="showewm" style="display: flex;flex-direction: column;align-items: center;">
				<image src="/static/images/icon_ewmc.png" style="width: 50rpx;height: 50rpx;" mode=""></image>
				<text style="margin-top: 10rpx;color: #515151;">
					二维码
				</text>
			</view>
			<view @click="scanqrcode" style="display: flex;flex-direction: column;align-items: center;">
				<image src="/static/images/icon_scancode.png" style="width: 50rpx;height: 50rpx;" mode=""></image>
				<text style="margin-top: 10rpx;color: #515151;">
					扫一扫
				</text>
			</view>
			<view @click="goSetting" style="display: flex;flex-direction: column;align-items: center;">
				<image src="/static/images/icon_set.png" style="width: 50rpx;height: 50rpx;" mode=""></image>
				<text style="margin-top: 10rpx;color: #515151;">
					设置
				</text>
			</view>
		</view>
		
		<u-popup @close="closePop" v-model="showChangeNote" mode="center" border-radius="16">
			<view style="padding: 30rpx;display: flex;flex-direction: column;width: 600rpx;">
				<view style="margin: 10rpx 0rpx 20rpx 0rpx;font-weight: 500;font-size: 36rpx;">
					设置签名
				</view>
				<u-input v-model="note" type="textarea" :border="true" />
				<view style="margin: 30rpx auto 10rpx auto;font-weight: 500;">
					<u-button @click="changeNote" shape="circle" type="primary" size="medium">确定</u-button>
				</view>
			</view>
		</u-popup>
		
		<u-popup v-model="showEwmStatus" mode="bottom" border-radius="16">
			<view style="padding: 30rpx;display: flex;flex-direction: column;width: 600rpx;">
				<view style="margin: 10rpx 0rpx 20rpx 0rpx;font-weight: 500;font-size: 36rpx;">
					我的二维码
				</view>
				<view style="margin: 50rpx auto 100rpx auto;width: 660rpx;display: flex;justify-content: center;background: #dee2fc;">
					<image :show-menu-by-longpress="true" :src="ewmsrc" style="width: 500rpx;" mode="widthFix"></image>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		name:"toolbar",
		data(){
			return {
				showChangeNote:false,
				showEwmStatus:false,
				note:'',
				ewmsrc:''
			}
		},
		mounted() {
			this.note = this.$store.state.user.user.note
		},
		methods:{
			scanqrcode:function(){
				const _this = this
				uni.scanCode({
					success: function (res) {
						if(res.scanType == "QR_CODE" && res.result.includes("user_id_")){
							const id = res.result.replace("user_id_","") * 1
							uni.navigateTo({
								url:"/pages/address/userinfo/index?fromType=扫码&id="+id
							})
							// uni.navigateTo({
							// 	url:"/pages/address/adduser/index?id="+id
							// })
						}else{
							_this.$u.toast(`无效的二维码`)
						}
					}
				});
			},
			showewm:async function(){
				const ewm = await this.$u.get(`common/common/getUserEwm/${this.$store.state.user.user.id}`)
				console.log(ewm)
				this.ewmsrc = ewm.data
				this.showEwmStatus = true
			},
			goSetting: function(){
				uni.navigateTo({
					url:"/pages/user/setting/index"
				})
			},
			changeNote:function(){
				this.$store.dispatch({
					type:"user/setUserNote",
					payload:{
						note:this.note
					}
				})
				this.showChangeNote = false
			},
			closePop:function(){
				
			},
			noteChange:function(e){
				console.log(e)
			}
		}
	}
</script>

<style>
</style>